package com.cvte.vdt.uartservice.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by wuguitong on 2018/12/1.
 */
public class SQLiteUtil extends SQLiteOpenHelper{
    private final static String DB_NAME = "bluetoothdevice.db";
    private final static int VERSION = 1;
    public final static String DB_TABLE_NAME = "bt_dev_table";
    public final static String BT_DEV_MAC = "mac";
    public final static String BT_DEV_NAME = "name";
    public final static String BT_STATUS = "status";


    public SQLiteUtil(Context context){
        super(context,DB_NAME,null,VERSION);
    }

    public SQLiteUtil(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table if not exists " + DB_TABLE_NAME +
                "("
                + BT_DEV_MAC + " text primary key, "
                + BT_DEV_NAME + " text, "
                + BT_STATUS + " integer"
                + ");";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        String deteleSql = "drop table if exists " + DB_TABLE_NAME;
        db.execSQL(deteleSql);
        onCreate(db);
    }
}
